﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MyRun.Controls
{
    public partial class SportRunButton : UserControl
    {
        public SportRunButton()
        {
            InitializeComponent();
        }

        private void DragMoveBehavier_TargetComplete(object sender, EventArgs e)
        {
            if (End != null)
            {
                End(sender, e);
            }
        }

        public event EventHandler End;
        public event EventHandler Pause;
        public event EventHandler Start;
        public event EventHandler Begin;

        private void button_Tap(object sender, GestureEventArgs e)
        {
            if (Begin != null)
            {
                Begin(sender, e);
            }
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if (Start != null && dragMove.CompleteValue == 0)
            {
                Start(sender, e);
            }
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            if (Pause != null && dragMove.CompleteValue == 0)
            {
                Pause(sender, e);
            }
        }

        public void Initial()
        {
            button.Opacity = 1;
            grid.Opacity = 0;
            chkPause.IsChecked = true;
            dragMove.CompleteValue = 0;
            dragMove.HasTargetComplete = false;
        }

        private void dragMove_TargetCompleting(object sender, EventArgs e)
        {
            if (chkPause.IsChecked == false)
            {
                if (Start != null && dragMove.CompleteValue == 0)
                {
                    Start(null, null);
                }
                else
                {
                    chkPause.IsChecked = false;
                }
            }
            else
            {
                if (Pause != null && dragMove.CompleteValue == 0)
                {
                    Pause(null, null);
                }
                else
                {
                    chkPause.IsChecked = true;
                }
            }
        }
    }
}
